<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
 <head>
  <meta http-equiv="content-type" content="text/html; charset=UTF-8">
  <title>如果对象属于该类或该类是此对象的父类则返回 TRUE</title>

 </head>
 <body><div class="manualnavbar" style="text-align: center;">
 <div class="prev" style="text-align: left; float: left;"><a href="function.interface-exists.html">interface_exists</a></div>
 <div class="next" style="text-align: right; float: right;"><a href="function.is-subclass-of.html">is_subclass_of</a></div>
 <div class="up"><a href="ref.classobj.html">类/对象 函数</a></div>
 <div class="home"><a href="index.html">PHP Manual</a></div>
</div><hr /><div id="function.is-a" class="refentry">
 <div class="refnamediv">
  <h1 class="refname">is_a</h1>
  <p class="verinfo">(PHP 4 &gt;= 4.2.0, PHP 5)</p><p class="refpurpose"><span class="refname">is_a</span> &mdash; <span class="dc-title">如果对象属于该类或该类是此对象的父类则返回 <strong><code>TRUE</code></strong></span></p>

 </div>
 <div class="refsect1 unknown-seealsp" id="refsect1-function.is-a-unknown-seealsp">
  <h3 class="title">说明</h3>
  <div class="methodsynopsis dc-description">
   <span class="type">bool</span> <span class="methodname"><strong>is_a</strong></span>
    ( <span class="methodparam"><span class="type">object</span> <code class="parameter">$object</code></span>
   , <span class="methodparam"><span class="type">string</span> <code class="parameter">$class_name</code></span>
   )</div>

  <p class="para rdfs-comment">
   如果对象是该类或该类是此对象的父类则返回 <strong><code>TRUE</code></strong>，否则返回 <strong><code>FALSE</code></strong>。
  </p>
  <p class="para">
    <div class="example" id="example-4961">
      <p><strong>Example #1 <span class="function"><strong>is_a()</strong></span> 例子</strong></p>
      <div class="example-contents">
<div class="phpcode"><code><span style="color: #000000">
<span style="color: #0000BB">&lt;?php<br /></span><span style="color: #FF8000">//&nbsp;define&nbsp;a&nbsp;class<br /></span><span style="color: #007700">class&nbsp;</span><span style="color: #0000BB">WidgetFactory<br /></span><span style="color: #007700">{<br />&nbsp;&nbsp;var&nbsp;</span><span style="color: #0000BB">$oink&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #DD0000">'moo'</span><span style="color: #007700">;<br />}<br /><br /></span><span style="color: #FF8000">//&nbsp;create&nbsp;a&nbsp;new&nbsp;object<br /></span><span style="color: #0000BB">$WF&nbsp;</span><span style="color: #007700">=&nbsp;new&nbsp;</span><span style="color: #0000BB">WidgetFactory</span><span style="color: #007700">();<br /><br />if&nbsp;(</span><span style="color: #0000BB">is_a</span><span style="color: #007700">(</span><span style="color: #0000BB">$WF</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">'WidgetFactory'</span><span style="color: #007700">))&nbsp;{<br />&nbsp;&nbsp;echo&nbsp;</span><span style="color: #DD0000">"yes,&nbsp;\$WF&nbsp;is&nbsp;still&nbsp;a&nbsp;WidgetFactory\n"</span><span style="color: #007700">;<br />}<br /></span><span style="color: #0000BB">?&gt;</span>
</span>
</code></div>
      </div>

    </div>
  </p>
  <p class="para">
   <span class="function"><strong>is_a()</strong></span> 函数已废弃，自 PHP 5 起请使用
   <a href="language.operators.type.html" class="link">instanceof</a>
   类型运算符。上例在 PHP 5 中会是这样：
  </p>
  <p class="para">
   <div class="example" id="example-4962">
    <p><strong>Example #2 在 PHP 5 中使用 <em class="emphasis">instanceof</em> 运算符</strong></p>
    <div class="example-contents">
<div class="phpcode"><code><span style="color: #000000">
<span style="color: #0000BB">&lt;?php<br /></span><span style="color: #007700">if&nbsp;(</span><span style="color: #0000BB">$WF&nbsp;</span><span style="color: #007700">instanceof&nbsp;</span><span style="color: #0000BB">WidgetFactory</span><span style="color: #007700">)&nbsp;{<br />&nbsp;&nbsp;&nbsp;&nbsp;echo&nbsp;</span><span style="color: #DD0000">'Yes,&nbsp;$WF&nbsp;is&nbsp;a&nbsp;WidgetFactory'</span><span style="color: #007700">;<br />}<br /></span><span style="color: #0000BB">?&gt;</span>
</span>
</code></div>
    </div>

   </div>
  </p>
  <p class="simpara">
   参见 <span class="function"><a href="function.get-class.html" class="function">get_class()</a></span>，<span class="function"><a href="function.get-parent-class.html" class="function">get_parent_class()</a></span> 和 
   <span class="function"><a href="function.is-subclass-of.html" class="function">is_subclass_of()</a></span>。
  </p>
 </div>

</div><hr /><div class="manualnavbar" style="text-align: center;">
 <div class="prev" style="text-align: left; float: left;"><a href="function.interface-exists.html">interface_exists</a></div>
 <div class="next" style="text-align: right; float: right;"><a href="function.is-subclass-of.html">is_subclass_of</a></div>
 <div class="up"><a href="ref.classobj.html">类/对象 函数</a></div>
 <div class="home"><a href="index.html">PHP Manual</a></div>
</div></body></html>
